from django.db import models

# Create your models here.

class User(models.Model):
    username = models.CharField(u'用户名',max_length=10)
    password = models.CharField(u'密码',max_length=15)
    email = models.EmailField(u'邮箱')
    phone = models.CharField(u'电话',max_length=11)
    def __str__(self):
        return str(self.id)

class Article(models.Model):
    title = models.CharField(u'标题',max_length=20)
    content = models.TextField(u'内容')
    author  = models.ForeignKey(User,related_name='article_column',on_delete=models.CASCADE)
    # 评论数量
    comment = models.IntegerField(u'评论数量',default=0)
    # 点赞数量
    fabulous = models.IntegerField(u'点赞数量',default=0)
    #浏览量
    article_views = models.IntegerField(u'浏览量',default=0)
    # avatar = models.ImageField(upload_to='%Y%m%d/', blank=True)
    mod_date = models.DateTimeField('最后修改时间', auto_now = True)
    def __str__(self):
        return str(self.id)

class Dian_zan(models.Model):

    artid = models.ForeignKey(Article,related_name='comment_id',null=True,blank=True,on_delete=models.CASCADE)#文章id
    userid = models.ForeignKey(User,related_name='user_id',on_delete=models.CASCADE)#评论者id
    stutas = models.BooleanField('点赞状态',default=True)
    times = models.DateTimeField('最后修改时间',auto_now = True)

    def __str__(self):
        return str(self.id)

class Art_comment(models.Model):

    art_id = models.ForeignKey(Article,related_name='comment_column',null=True,blank=True,on_delete=models.CASCADE)#文章id
    user_id = models.ForeignKey(User,related_name='user_column',on_delete=models.CASCADE)#评论者id
    send_obj = models.ForeignKey(to='self',null=True,blank=True,on_delete=models.CASCADE)#评论对象
    content = models.CharField(max_length=250)#内容
    com_time = models.DateTimeField()#时间

    def __str__(self):
        return str(self.id)

class ver_email(models.Model):
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    code = models.CharField(u'验证码',max_length=10)#验证码
    def __str__(self):
        return str(self.id)